package edu.gdkm.dao;

import edu.gdkm.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao {

    // 根据ID查询
    @Select("SELECT * FROM Users WHERE user_id = #{userId}")
    User selectById(Integer userId);

    // 查询所有用户
    @Select("SELECT * FROM Users")
    List<User> selectAll();

    // 新增用户
    @Insert("INSERT INTO Users(username, email, password_hash, full_name, phone, created_at, updated_at, last_login, status, profile_image) " +
            "VALUES(#{username}, #{email}, #{passwordHash}, #{fullName}, #{phone}, #{createdAt}, #{updatedAt}, #{lastLogin}, #{status}, #{profileImage})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    int insert(User user);

    // 更新用户
    @Update("UPDATE Users SET username = #{username}, email = #{email}, password_hash = #{passwordHash}, " +
            "full_name = #{fullName}, phone = #{phone}, updated_at = #{updatedAt}, last_login = #{lastLogin}, " +
            "status = #{status}, profile_image = #{profileImage} WHERE user_id = #{userId}")
    int update(User user);

    // 删除用户
    @Delete("DELETE FROM Users WHERE user_id = #{userId}")
    int delete(Integer userId);
    @Select("SELECT * FROM Users WHERE status = #{status}")
    List<User> selectByStatus(String active);
}
    